/**
 * @todo
 */
#include <stdio.h>
#include <stdlib.h>

void pai_lie()
{
    int
    m,
    n,
    t1 = 1,
    t2 = 1;

    int count = 0;

    printf("Please enter the following numbers:\n");

    // TODO
    printf("Total n: ");
    scanf("%d", &n);

    printf("situation m: ");
    scanf("%d", &m);

    for (unsigned char i = 1; i <= n - m; i++) {
        t1 *= i;
    }
    for (unsigned char i = 1; i <= n; i++) {
        t2 *= i;
    }

    count = t2 / t1;

    printf("Result is: %d\n", count);
    system("PAUSE");
}

void zu_he()
{
    int
    m,
    n,
    t1 = 1,
    t2 = 1,
    t3 = 1;

    int count = 0;

    printf("Please enter the following numbers:\n");

    printf("Total n: ");
    scanf("%d", &n);

    printf("situation m: ");
    scanf("%d", &m);

    for (unsigned char i = 1; i <= m; i++) {
        t1 *= i;
    }
    for (unsigned char i = 1; i <= n; i++) {
        t2 *= i;
    }
    for (unsigned char i = 1; i <= n - m; i++) {
        t3 *= i;
    }

    count = t2 / (t1 * t3);

    printf("Result is: %d\n", count);
    system("PAUSE");
}

void op_arrangement_init()
{
    unsigned char selected;

    // Draw UI
    ui_cls();
    ui_add_empty_line(1);
    ui_add_border_line_text("Arrangement method selection");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("1: Arrangement A(m, n)");
    ui_add_border_row_empty(1);
    ui_add_opt_desc("2: Combination C(m, n)");
    ui_add_border_row_empty(2);
    ui_add_opt_desc("3: Back to calculator start");
    ui_add_border_row_empty(1);
    ui_add_border_line_single();
    ui_add_empty_line(1);
    printf("Please enter the operation number you want [1 ~ 3]: ");

    scanf("%d", &selected);
    switch (selected)
    {
    case 1:
        pai_lie();
        break;
    case 2:
        zu_he();
        break;
    case 3:
        index_start();
        break;
    default:
        ui_cls();
        printf("What you had selected is %d, which is incorrect.\n", selected);
        system("PAUSE");
        op_arrangement_init();
    }
}
